"""
中值滤波模块

实现了中值滤波算法用于信号平滑处理
"""

import numpy as np
from typing import Union
from loguru import logger
from scipy import signal


class MedianFilter:
    """中值滤波器"""
    
    def __init__(self, window_size: int = 5):
        """
        初始化中值滤波器
        
        Args:
            window_size: 窗口大小
        """
        self.window_size = window_size
        logger.info(f"初始化中值滤波器，窗口大小={window_size}")
    
    def filter(self, data: np.ndarray) -> np.ndarray:
        """
        应用中值滤波
        
        Args:
            data: 输入数据
            
        Returns:
            滤波后的数据
        """
        return signal.medfilt(data, self.window_size)
    
    def filter_2d(self, data: np.ndarray) -> np.ndarray:
        """
        应用2D中值滤波
        
        Args:
            data: 2D输入数据
            
        Returns:
            滤波后的2D数据
        """
        return signal.medfilt2d(data, self.window_size)
    
    def __str__(self) -> str:
        return f"MedianFilter(window_size={self.window_size})" 